﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Accountability4net
{
    public class EventedList<T>: List<T>
    {
        public event ListChangedEventHandler ListChanged;
        public new void Add(T item)
        {
            base.Add(item);
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, Count - 1));
        }

        public new void Insert(int index, T item)
        {
            base.Insert(index, item);
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
        }

        public new void RemoveAt(int index)
        {
            base.RemoveAt(index);
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
        }

        public new void Clear()
        {
            base.Clear();
            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0));
        }

        protected void OnListChanged(ListChangedEventArgs e)
        {
            if (ListChanged != null)
            {
                ListChanged(this, e);
            }
        }
    }
}
